package service;

import domain.Account;
import persistence.AccountDao;
import persistence.impl.AccountDaoImpl;

public class AccountService {

    public Account getAccount(String username) {
        return new AccountDaoImpl().getAccountByUsername(username);
    }

    public Account getAccount(String username, String password) {
        Account account = new Account();
        account.setUsername(username);
        account.setPassword(password);
        return new AccountDaoImpl().getAccountByUsernameAndPassword(account);
    }

    public void insertAccount(Account account) {
        new AccountDaoImpl().insertAccount(account);
        new AccountDaoImpl().insertProfile(account);
        new AccountDaoImpl().insertSignon(account);
    }

    public void updateAccount(Account account) {
        new AccountDaoImpl().updateAccount(account);
        new AccountDaoImpl().updateProfile(account);

        if (account.getPassword() != null && account.getPassword().length() > 0) {
            new AccountDaoImpl().updateSignon(account);
        }
    }
}
